package com.dingding.manager.modules.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.manager.common.beans.SysProvince;
import com.dingding.manager.core.shiro.ShiroKit;
import com.dingding.manager.core.shiro.ShiroUser;
import com.dingding.manager.core.util.ToolUtil;
import com.dingding.manager.modules.system.dao.ProvinceAndCityDao;
import com.dingding.manager.modules.system.dto.proandcity.CityDTO;
import com.dingding.manager.modules.system.dto.proandcity.ProIdAndCityIdDTO;
import com.dingding.manager.modules.system.service.ProvinceAndCityService;
import com.dingding.manager.modules.system.sql.ProAndCitySQL;

/**
 * 
 * @Description: 省份城市级联查询Service
 * @author haoxiaojun
 * @date 2016年12月3日 上午11:43:07
 * @since V 2.5.7
 */
@Service("provinceAndCityService")
public class ProvinceAndCityServiceImpl implements ProvinceAndCityService {

	private Logger log = Logger.getLogger(this.getClass());

	@Resource(name = "provinceAndCityDao")
	private ProvinceAndCityDao provinceAndCityDao;

	/**
	 * 
	 * @Description: 获取所有省份信息
	 * @author haoxiaojun
	 * @date 2016年12月3日 上午11:23:24
	 * @since V 2.5.7
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	public List<SysProvince> getProvince() {
		
		return provinceAndCityDao.getProvince();
		
	}

	
	/**
	 * 
	 * @Description: 根据省份Id获取当前省份下的所有城市
	 * @author haoxiaojun
	 * @date 2016年12月3日 上午11:42:27
	 * @since V 2.5.7
	 */
	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public List<CityDTO> getCity(Integer provice_id) {
		
		if (ToolUtil.isEmpty(provice_id)) {
			return null;
		}
		
		StringBuffer cityListSQL = new StringBuffer(ProAndCitySQL.GET_CITY_BY_ID);
		List<Integer> parms = new ArrayList<>();
		
		if (ToolUtil.isNotEmpty(provice_id)) {
			cityListSQL.append(" AND c.provice_id = ? ");
			parms.add(provice_id);
		}
		
		String sql = cityListSQL.toString();
		
		return provinceAndCityDao.getCity(parms, sql);
		
	}

	/**
	 * 
	 * @Title: getSysProvinceById 
	 * @Description: 根据省份id查询省份信息
	 * @param  参数说明 
	 * @author hufan
	 * @return 返回类型 
	 * @throws
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public SysProvince getSysProvinceById(Integer provinceId) {
		return provinceAndCityDao.getSysProvinceById(provinceId);
	}

	/**
	 * 
	* @Description: 根据公司Id查询城市和省份信息
	* @author haoxiaojun 
	* @date 2016年12月13日 下午4:30:10
	* @since V 2.5.7
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public ProIdAndCityIdDTO getProIdAndCityIdByCompanyId(Integer companyId) {
		return provinceAndCityDao.getProIdAndCityIdByCompanyId(companyId);
	}



}
